/*
 *
 * Copyright (c) 2023 - future
 * @author fzh
 * @email e_341877120_mail@163.com
 * @link https://mvnrepository.com/search?q=io.github.xrfzh.cn
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package cn.xrfzh.biz.video.controller;

import cn.xrfzh.api.video.dto.VideoQueryDto;
import cn.xrfzh.common.annotation.ConfirmExecuteAPI;
import cn.xrfzh.common.annotation.SystemLog;
import cn.xrfzh.common.enums.LogType;
import cn.xrfzh.trafficLimit.annotation.TrafficLimit;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.annotations.ApiOperation;
import cn.xrfzh.common.axios.AxiosResult;
import cn.xrfzh.common.axios.AxiosEnum;
import cn.xrfzh.api.video.dto.VideoDto;
import cn.xrfzh.biz.video.service.IVideoService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用于存储视频信息
 *
 * @author fzh
 * @email e_341877120_mail@163.com
 * @date 2023-10-24 08:34:41
 */
@Api(tags = "video模块")
@RestController
@RequestMapping("/api/v1/video")
@RequiredArgsConstructor
public class VideoController {

    private final IVideoService iVideoService;

    /**
     * 根据id查询单个
     *
     * @param id
     * @return
     */
    // @SaCheckPermission("pmi:video:selectonebyid")
    @ApiOperation(value = "根据id查询Video信息")
    @GetMapping("/selectOneById/{id}")
    public AxiosResult selectOneById(@PathVariable Long id) {
        return iVideoService.selectOneById(id);
    }

    /**
     * 更新
     *
     * @param videoDto
     * @return
     */
    // @SaCheckPermission("pmi:video:update")
    @SystemLog(module = "video模块", type = LogType.UPDATE, description = "更新Video信息")
    @ApiOperation(value = "更新Video信息")
    @PutMapping("/update")
    public AxiosResult update(@RequestBody VideoDto videoDto) {
        return iVideoService.update(videoDto);
    }

    /**
     * 根据id删除单个
     *
     * @param id
     * @return
     */
    // @SaCheckPermission("pmi:video:delete")
    @SystemLog(module = "video模块", type = LogType.DELETE, description = "删除Video信息")
    @ApiOperation(value = "删除Video信息")
    @DeleteMapping("/delete/{id}")
    public AxiosResult delete(@PathVariable Long id) {
        return iVideoService.delete(id);
    }

    /**
     * 根据id集合批量删除
     *
     * @param idList
     * @return
     */
    // @SaCheckPermission("pmi:video:deletebatch")
    @SystemLog(module = "video模块", type = LogType.DELETE, description = "批量删除Video信息")
    @ApiOperation(value = "批量删除Video信息")
    @PostMapping("/deleteBatch")
    public AxiosResult deleteBatch(@RequestBody List<Long> idList) {
        return iVideoService.deleteBatch(idList);
    }

    /**
     * 导入文件
     *
     * @param file
     * @return
     */
    // @SaCheckPermission("pmi:video:import")
    @SystemLog(module = "video模块", type = LogType.IMPORT, description = "导入Video信息")
    @ApiOperation(value = "导入Video信息")
    @PostMapping("/importFile")
    public AxiosResult importFile(@RequestBody MultipartFile file) {
        return iVideoService.importFile(file);
    }

    /**
     * 导出文件
     *
     * @param response
     * @return
     */
    // @SaCheckPermission("pmi:video:export")
    @SystemLog(module = "video模块", type = LogType.EXPORT, description = "导出Video信息")
    @ApiOperation(value = "导出Video信息")
    @GetMapping("/exportFile")
    public AxiosResult exportFile(HttpServletResponse response) {
        iVideoService.exportFile(response);
        return AxiosResult.success(AxiosEnum.EXPORT_SUCCESS);
    }

    /**
     * 上传Video
     *
     * @param file
     * @return
     */
    @ConfirmExecuteAPI
    @SystemLog(module = "video模块", type = LogType.UPLOAD, description = "上传Video")
    @ApiOperation(value = "上传Video")
    @PostMapping("/uploadVideo")
    public AxiosResult uploadVideo(@RequestPart("file") MultipartFile file) {
        return iVideoService.uploadVideo(file);
    }

    /**
     * 根据内容分类查询对应类别的视频（分页）
     *
     * @param currentPage
     * @param pageSize
     * @param videoDto
     * @return
     */
    @ConfirmExecuteAPI
    @ApiOperation(value = "分页查询Video信息")
    @GetMapping("/selectPage/{currentPage}/{pageSize}")
    public AxiosResult selectPage(@PathVariable int currentPage, @PathVariable int pageSize, VideoDto videoDto) {
        return iVideoService.selectPage(currentPage, pageSize, videoDto);
    }

    /**
     * 用户发布视频
     *
     * @param videoDto
     * @return
     */
    @ConfirmExecuteAPI
    @SystemLog(module = "video模块", type = LogType.INSERT, description = "用户发布视频")
    @ApiOperation(value = "用户发布视频")
    @PostMapping("/insert")
    public AxiosResult insert(@RequestBody @Validated VideoDto videoDto) {
        return iVideoService.insert(videoDto);
    }

    /**
     * 查询当前视频的点赞量和收藏量
     *
     * @param videoId
     * @return
     */
    @ConfirmExecuteAPI
    @TrafficLimit(ttl = 1, threshold = 10)
    @ApiOperation(value = "查询当前视频的点赞量和收藏量")
    @GetMapping("/getInteractionNumber/{videoId}")
    public AxiosResult getInteractionNumber(@PathVariable int videoId) {
        return iVideoService.getInteractionNumber(videoId);
    }

    /**
     * 根据内容分类查询对应类别的视频（不分页）
     *
     * @param videoQueryDto
     * @return
     */
    @ConfirmExecuteAPI
    @ApiOperation(value = "查询Video信息")
    @GetMapping("/selectList")
    public AxiosResult selectList(VideoQueryDto videoQueryDto) {
        return iVideoService.selectList(videoQueryDto);
    }

}
